package com.example.youjingjing.electronicbalance.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;

import java.util.List;

/**
 * Created by youjingjing on 2017/7/20.
 */

public class MyFragmentStatePagerAdapter<T extends Fragment> extends FragmentStatePagerAdapter {

    List<T> fragments;
    String[] title;

    public MyFragmentStatePagerAdapter(FragmentManager fm, List<T> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    public MyFragmentStatePagerAdapter(FragmentManager fm, List<T> fragments, String[] title) {
        super(fm);
        this.fragments = fragments;
        this.title = title;
    }
    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object obj) {
        return view == ((Fragment) obj).getView();
    }
}
